Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
Scoop Box Exchange - Show Box: hotlist_flex+diaries K5 style 1.00

Author: rusty [Info]

Description:

hillct's hotlist_flex+diaries, modified for high-volume use on K5. Some queries streamlined and rewritten, it's generally faster and more efficient. Watch out for

Box Code:

## START hotlist_flex+diary ##
# Display Hotlist, Stories and unread replies to user comments
# Version 0.3.1 by hillct
return unless ($S->have_perm('hotlist_flex'));
my($view,$content,$item);
my $uri=$S->{APACHE}->uri;
my $arg = $S->apache->args();
$arg =~ s/set-view=\w+//g;
$arg =~ s/;$//;

$uri .= ($arg) ? "?$arg;" : '?';

if($S->{GID} ne 'Anonymous') { # Only if we're logged in
if($S->{CGI}->param('set-view')=~/Hotlist\|Replies\|Stories\|Diaries/){
$view=$S->{CGI}->param('set-view');
$S->session('hotlist-view',$view);
} else {$view = $S->session('hotlist-view') \|\| 'Hotlist';}

$content="<center>";
for ('Hotlist','Replies','Stories','Diaries'){
$content.=(($_ eq $view)?"<b>$_</b> \| ":"<a
href=\"$uri"."set-view=$_\">$_</a> \| ");
}
$content =~ s/\\|\s$//;
$content.="</center>";

if($view eq 'Hotlist'){
$content .= '<p>';


if ($S->{HOTLIST} && $#{$S->{HOTLIST}} >= 0) {
$content .= qq{
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=1 CELLSPACING=0>};

foreach my $sid (@{$S->{HOTLIST}}) {
my $stories = $S->getstories(
{-type => 'fullstory',
-sid => $sid});
my $story = $stories->[0];

my $show = $S->{UI}->{VARS}->{show_new_comments};
my $num_new = $S->new_comments_since_last_seen($sid) if
($show eq "hotlist" \|\| $show eq "all");

my $end_s = ($story->{commentcount} == 1) ? '' : 's';
$content .= qq{
<TR>
<TD VALIGN="top"><A HREF="|rootdir|/hotlist/remove/$sid/displaystory">|hotlist_remove_link|</A></TD><TD>|norm_font|<A CLASS="light" HREF="|rootdir|/story/$sid">$story->{title}</A><BR>($story->{commentcount} comment$end_s};
$content .= ", <B>$num_new</B> new" if defined($num_new);
$content .= qq{)|norm_font_end|</TD>
</TR>};
}
$content .= qq{
</TABLE>};

} else{ $content.="<font size=1>No Hotlisted Stories</font>"; }
}elsif($view eq 'Replies'){
$content .= '<p>';

my($results,$comment,$sid);
my ($rv, $sth) = $S->db_select({
WHAT => 'c1.sid,c2.cid,c2.subject',
FROM => 'comments AS c1 LEFT JOIN comments as c2 on c2.sid=c1.sid
AND c2.pid=c1.cid LEFT JOIN viewed_stories ON viewed_stories.sid=c1.sid
AND viewed_stories.uid=c1.uid',
WHERE => qq{c1.uid=$S->{UID} AND c2.sid IS NOT NULL AND c2.date > DATE_SUB(NOW(), INTERVAL 14 DAY) AND c2.cid > viewed_stories.highest_idx}
});

while ($comment = $sth->fetchrow_hashref()) {
$results->{$comment->{'sid'}}.=qq{
<br>|dot|
<a href="|rootdir|/comments/$comment->{'sid'}/$comment->{'cid'}#$comment->{'cid'}"><font size="1">$comment->{'subject'}</font></a> };
}
my $reply_txt;
for $sid (keys %$results){
my ($rv, $sth) = $S->db_select({
WHAT => 'title, displaystatus',
FROM => 'stories',
WHERE => qq{sid = "$sid"}
});
my ($title, $disp) = $sth->fetchrow();
$sth->finish();
next if ($disp == -1);
$reply_txt .= qq{
<p>
<a href="|rootdir|/story/$sid"><font
size="2">$title</font></a>
$results->{$sid}
</p>
};

}

$content .= $reply_txt \|\| qq{<font size="1">No New Replies to your Comments</font>};

}elsif($view eq 'Stories'){
$content.='<p>';
my ($results,$story);
my ($rv, $sth) = $S->db_select({
WHAT => 'stories.title,stories.sid,stories.section,COUNT(comments.cid) AS commentcount',
FROM => 'stories LEFT JOIN comments ON comments.sid=stories.sid',
WHERE => qq{aid='$S->{NICK}' AND time >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND displaystatus != '-1'},
GROUP_BY => 'stories.sid',
ORDER_BY => 'time DESC'
});

my $linknick = $S->urlify($S->{NICK});
my $stories_text;
my ($story_count, $diary_count);
while ($story = $sth->fetchrow_hashref()) {
my $sid=$story->{sid};
if ($story->{section} eq 'Diary') {
$diary_count++;
} elsif ($story->{section} ne 'advertisements') {
$story_count++;
}
my $show = $S->{UI}->{VARS}->{show_new_comments};
my $num_new = $S->new_comments_since_last_seen($sid) if
($show eq "hotlist" \|\| $show eq "all");

my $end_s = ($story->{commentcount} == 1) ? '' : 's';
$stories_text .= qq{
<TR>
<TD VALIGN="top">|dot|</td>
<td valign="top">|norm_font|<a class="light" href="|rootdir|/story/$sid">$story->{title}</a><br>($story->{commentcount}
comment$end_s};
$stories_text .= qq{, <b>$num_new</b> new} if defined($num_new);
$stories_text .= qq{)|norm_font_end|</td></tr>};
}

if ($stories_text) {
$content .= qq{
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=1 CELLSPACING=0>
$stories_text
</TABLE>
<p>
Older: <a href="|rootdir|/?op=search&offset=$story_count&old_count=0&type=author&topic=§ion=&string=$linknick&count=30&next=Next+Page+%3E%3E">Stories</a>,
<a href="|rootdir|/?op=search&offset=$diary_count&old_count=0&type=diary_by&topic=§ion=&string=$linknick&count=30&next=Next+Page+%3E%3E">Diaries</a>};
} else {
$content.="<font size=1>You have written no stories in the last 30 days.</font>";
}
#"
}elsif($view eq 'Diaries'){
$content.='<p>';
my @subscriptions=split(/,/,$S->pref('diary_sub'));

my $authors;
my @sids;
my $titles;
foreach my $auth (sort @subscriptions) {
my ($rv, $sth) = $S->db_select({
DEBUG=> 0,
WHAT => 'aid, sid, title',
FROM => 'stories',
WHERE => qq{aid="$auth" AND time >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND section='Diary'},
ORDER_BY => 'time desc'
});


while (my ($aid, $sid, $title) = $sth->fetchrow()) {
next if (defined $S->story_last_seen($sid));
push @sids, $sid;
push @{$authors->{$aid}}, $sid;
if (length($title) > 25) {
$title =~ s/^(.{25}).*$/$1.../;
}
$titles->{$sid} = $title;
}
$sth->finish();

}

foreach my $author (@subscriptions) {
my $l_author = $S->urlify($author);
my $new = 0;
#warn "Author is $author, new is $new\n";
$content.=qq{<b><a href="|rootdir|/diary/$l_author">|hotlist_remove_link|</a> };
$content.=qq{<a href="|rootdir|/user/$l_author/diary">$author</a></b>};
#"
my $title_links;
foreach my $posted_sid (@{$authors->{$author}}) {
#warn "SID is $posted_sid, New is $new\n";
$new++;
$title_links .= qq{<br>|dot| <a href="/story/$posted_sid">$titles->{$posted_sid}</a>};
}

if ($new) {
$content .= qq{ (<b>$new</b> new) |smallfont|$title_links|smallfont_end|<br>};
} else {
$content .= qq{ (0 new)<br>};
}

}
$content.="<font size=1>You have no diaries on your watch list</font>" if $#subscriptions==-1;
}else{$content.="This error should never occur.";}
return {title => "$S->{NICK}'s $view", content => $content};
}

## END hotlist_flex+diary ##
Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Scoop Site Scroller: Get one yourself!
Scoop::Ads
Almost there...

Login
Make a new account
Username:
Password:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search